<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <!-- <keep-alive include="home,kind"> -->
    <!-- <keep-alive :include="/home|kind/"> -->
    <keep-alive :include="['home', 'kind']">
      <component :is="type"></component>
    </keep-alive>
    <ul>
      <li @click="changeTitle('home')">首页</li>
      <li @click="changeTitle('kind')">分类</li>
      <li @click="changeTitle('cart')">购物车</li>
      <li @click="changeTitle('user')">我的</li>
    </ul>
  </div>
</body>
<script src="lib/vue.js"></script>
<script>
  const Home = {
    name: 'home',
    template: `<div>首页<input type="text" placeholder="首页" /></div>`,
    mounted () { console.log('首页 mounted')},
    activated() {console.log('home  activated')},
    deactivated() {console.log('home  deactivated')},
  }
  const Kind = {
    name: 'kind',
    template: `<div>分类<input type="text" placeholder="分类" /></div>`,
    mounted () { console.log('分类 mounted')},
    activated() {console.log('kind  activated')},
    deactivated() {console.log('kind  deactivated')},
  }
  const Cart = {
    name: 'cart',
    template: `<div>购物车<input type="text" placeholder="购物车" /></div>`,
    mounted () { console.log('购物车 mounted()')},
    activated() {console.log('cart  activated')},
    deactivated() {console.log('cart  deactivated')},
  }
  const User = {
    name: 'user',
    template: `<div>我的<input type="text" placeholder="我的" /></div>`,
    mounted () { console.log('我的 mounted')},
    activated() {console.log('user  activated')},
    deactivated() {console.log('user  deactivated')},
  }

  new Vue({
    el: '#app',
    data: {
      type: 'home'
    },
    components: {
      Home: Home,
      Kind: Kind,
      Cart: Cart,
      User: User
    },
    methods: {
      changeTitle (type) {
        this.type = type
      }
    },
  })
</script>
</html>